﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Reporting.WebForms;

namespace WebReports
{
    public partial class OperationReport : System.Web.UI.Page
    {
        private int devType = 0;
        private string reportName = "";
        private int devId = 0;
        protected void Page_Load(object sender, EventArgs e)
        {  // 页面加载时的处理

            devType = Convert.ToInt32(this.Context.Request["devtype"]);
            if (string.IsNullOrEmpty(Context.Request["report"]) == false)
            {
                reportName = this.Context.Request["report"].ToString();
            }
            if (string.IsNullOrEmpty(Context.Request["td_id"]) == false)
            {
                devId = Convert.ToInt32(this.Context.Request["td_id"]);
            }
        }
        protected void timeend(object sender, EventArgs e)
        {
            LoadReport();
        }
        protected void LoadReport()
        {

            RV_REPORT.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote;
            RV_REPORT.ShowCredentialPrompts = true;
            ReportServerCredentials rpCredential = new ReportServerCredentials();
            RV_REPORT.ServerReport.ReportServerCredentials = rpCredential;
            RV_REPORT.ServerReport.ReportServerUrl = new Uri("http://localhost:9200/ReportServer");
            //RV_REPORT.ServerReport.ReportServerUrl = new Uri("http://61.155.174.99:9200/ReportServer");

            switch (reportName)
            {
                //case "T1_Power_Quality_Stats_Trends_Report":
                //    RV_REPORT.ServerReport.ReportPath = "/JSTTReport/Online_Reports/T1_REGULATING_DEVICE_STATS_REPORT/T1_Power_Quality_Stats_Trends_Report";
                //    break;
                //case "T2_Equipment_Operating_Trends_Report":
                //    RV_REPORT.ServerReport.ReportPath = "/JSTTReport/Online_Reports/T2_PASSIVE_COMPENSATION_AND_HARMONIC_CONTROL_DEVICES_REPORT/T2_Equipment_Operating_Trends_Report";
                //    break;
                //case "T3_Power_Quality_Stats_Trends_Report":
                //    RV_REPORT.ServerReport.ReportPath = "/JSTTReport/Online_Reports/T3_APF_POWER_QUALITY_STATS_REPORT/T3_Power_Quality_Stats_Trends_Report";
                //    break;
                //case "T4_Equipment_Operating_Trends_Report":
                //    RV_REPORT.ServerReport.ReportPath = "/JSTTReport/Online_Reports/T4_INTEGRATED_POWER_DISTRIBUTION_UNIT_REPORT/T4_Equipment_Operating_Trends_Report";
                //    break;
                case "T1_Power_Quality_Stats_Trends_Report":
                    RV_REPORT.ServerReport.ReportPath = "/JSTTReport/Online_Reports/Trends_Report/T1_Power_Quality_Stats_Trends_Report";
                    break;
                case "T2_Equipment_Operating_Trends_Report":
                    RV_REPORT.ServerReport.ReportPath = "/JSTTReport/Online_Reports/Trends_Report/T2_Equipment_Operating_Trends_Report";
                    break;
                case "T3_Power_Quality_Stats_Trends_Report":
                    RV_REPORT.ServerReport.ReportPath = "/JSTTReport/Online_Reports/Trends_Report/T3_Power_Quality_Stats_Trends_Report";
                    break;
                case "T4_Equipment_Operating_Trends_Report":
                    RV_REPORT.ServerReport.ReportPath = "/JSTTReport/Online_Reports/Trends_Report/T4_Equipment_Operating_Trends_Report";
                    break;
                default:
                    return;
            }
            //DateTime dt = new DateTime();
            //if (Timestar.Text != "")
            //{
            //    dt = Convert.ToDateTime(Timestar.Text);
            //}
            //if (Timeend.Text != "")
            //{
            //    dt = Convert.ToDateTime(Timeend.Text);
            //}

            ReportParameter[] p = new ReportParameter[3];

            p[0] = new ReportParameter("startime", Timestar.Text.ToString(), false);
            p[1] = new ReportParameter("endtime", Timeend.Text.ToString(), false);
            p[2] = new ReportParameter("devtype", devId.ToString());
            RV_REPORT.ServerReport.SetParameters(p);

            RV_REPORT.ShowParameterPrompts = false;
            RV_REPORT.ServerReport.Refresh();
        }
        protected void Time_TextChanged(object sender, EventArgs e)
        {

        }
    }
}